﻿using EBA.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using System.Text;

namespace EBA.Tests.Framework
{
    [TestClass]
    public class BundleInstallerTest
    {
        [TestMethod]
        public void test_install_bundle()
        {
            using (var config = ConfigHelper.Create())
            {
                var bundleId = "Bundle_E73E0510645542AA95906BC9F1F6B4BB";

                using (var installer = new BundleInstaller<IBundle>(config.FileName))
                {
                    var manifest = new BundleManifest(new Bundle_E73E0510645542AA95906BC9F1F6B4BB())
                    {
                        Files = new List<string> { Path.Combine(AppRuntime.ApplicationPath, "EBA.Tests.dll") }
                    };

                    installer.Install(manifest);

                    var framework = new FrameworkConfiguration(config.FileName);

                    var bundleConfig = framework.Framework.Bundles.AsEnumerable.Where(i => i.Id == bundleId).Single();


                    Assert.IsTrue(bundleConfig.Files.Count == 1);
                    Assert.IsTrue(bundleConfig.Files.AsEnumerable.Any(i => i.Name.EndsWith("EBA.Tests.dll")));
                }
            }
        }

        #region Helpers

        [Export("Bundle_E73E0510645542AA95906BC9F1F6B4BB", typeof(IBundle))]
        public class Bundle_E73E0510645542AA95906BC9F1F6B4BB : IBundle
        {

            public IBundleContext BundleContext
            {
                get;
                set;
            }

            public void Start()
            {
                throw new NotImplementedException();
            }

            public void Stop()
            {
                throw new NotImplementedException();
            }

            public void Install()
            {
                throw new NotImplementedException();
            }

            public void Uninstall()
            {
                throw new NotImplementedException();
            }

            public void Update()
            {
                throw new NotImplementedException();
            }

            public string Id
            {
                get { return "Bundle_E73E0510645542AA95906BC9F1F6B4BB"; }
            }

            public string Name
            {
                get { return "BundleInstallerTest.Test_LoadBundleManifests"; }
            }

            public string Description
            {
                get { return "BundleInstallerTest.Test_LoadBundleManifests_description"; }
            }

            public Version Version
            {
                get { return new Version(0, 0, 1); }
            }


            public BundleState State
            {
                get { throw new NotImplementedException(); }
            }


            public string StartupPath
            {
                set { throw new NotImplementedException(); }
            }
        } 
        #endregion
    }
}
